library(zzlongplot)
library(ggplot2)
library(patchwork)
The zzlongplot package provides publication-ready themes
and color palettes specifically designed for major medical journals.
This vignette demonstrates the various themes available and shows how
they can be used to create professional, journal-ready figures.
theme parameterLet’s create a realistic clinical trial dataset to demonstrate the themes:
# Create comprehensive clinical trial dataset
set.seed(123)
n_subjects <- 90
n_visits <- 4
demo_data <- data.frame(
subject_id = rep(1:n_subjects, each = n_visits),
visit = rep(c(0, 4, 8, 12), times = n_subjects),
treatment = rep(c("Placebo", "Drug 10mg", "Drug 20mg"), each = n_visits * 30)
)
# Generate realistic clinical outcomes
for (subj in unique(demo_data$subject_id)) {
subj_rows <- which(demo_data$subject_id == subj)
treatment <- demo_data$treatment[subj_rows[1]]
# Baseline efficacy score
baseline <- 50 + rnorm(1, 0, 10)
# Treatment-specific efficacy improvements
if (treatment == "Placebo") {
effects <- c(0, 2, 3, 4) # Small placebo effect
} else if (treatment == "Drug 10mg") {
effects <- c(0, 8, 14, 18) # Moderate dose effect
} else { # Drug 20mg
effects <- c(0, 12, 22, 28) # High dose effect
}
# Generate data with realistic variability
demo_data$efficacy[subj_rows] <- baseline + effects + rnorm(4, 0, 8)
}
# Display data structure
str(demo_data)
#> 'data.frame': 360 obs. of 4 variables:
#> $ subject_id: int 1 1 1 1 2 2 2 2 3 3 ...
#> $ visit : num 0 4 8 12 0 4 8 12 0 4 ...
#> $ treatment : chr "Placebo" "Placebo" "Placebo" "Placebo" ...
#> $ efficacy : num 42.6 58.9 48 49.4 70.8 ...
head(demo_data, 12)
#> subject_id visit treatment efficacy
#> 1 1 0 Placebo 42.55382
#> 2 1 4 Placebo 58.86491
#> 3 1 8 Placebo 47.95931
#> 4 1 12 Placebo 49.42955
#> 5 2 0 Placebo 70.83798
#> 6 2 4 Placebo 59.03016
#> 7 2 8 Placebo 64.65583
#> 8 2 12 Placebo 67.58535
#> 9 3 0 Placebo 65.11933
#> 10 3 4 Placebo 67.44699
#> 11 3 8 Placebo 66.12628
#> 12 3 12 Placebo 61.79409
The NEJM theme provides professional, clinical styling with the journal’s official color palette.
p_nejm <- lplot(demo_data,
efficacy ~ visit | treatment,
cluster_var = "subject_id",
baseline_value = 0,
theme = "nejm",
title = "Clinical Efficacy Over Time",
subtitle = "NEJM Theme with Official Colors",
xlab = "Week",
ylab = "Efficacy Score (points)")
p_nejm
NEJM Theme Features: - Professional clinical appearance - Bold axis titles for clarity - Clean, no-grid design - Official NEJM color palette: Red (#BC3C29), Blue (#0072B5), Orange (#E18727)
The Nature theme follows Nature journal guidelines with modern, sophisticated styling.
p_nature <- lplot(demo_data,
efficacy ~ visit | treatment,
cluster_var = "subject_id",
baseline_value = 0,
theme = "nature",
title = "Clinical Efficacy Over Time",
subtitle = "Nature Theme with Official Colors",
xlab = "Week",
ylab = "Efficacy Score (points)")
p_nature
Nature Theme Features: - 7pt font size (Nature requirement) - Clean backgrounds with optional borders - Nature color palette: Cinnabar (#E64B35), Sky Blue (#4DBBD5), Persian Green (#00A087) - Professional scientific appearance
The Lancet theme provides distinctive styling with the journal’s recognizable color scheme.
p_lancet <- lplot(demo_data,
efficacy ~ visit | treatment,
cluster_var = "subject_id",
baseline_value = 0,
theme = "lancet",
title = "Clinical Efficacy Over Time",
subtitle = "Lancet Theme with Official Colors",
xlab = "Week",
ylab = "Efficacy Score (points)")
p_lancet
Lancet Theme Features: - Deep blue (#00468B) and Lancet red (#ED0000) signature colors - Professional medical journal styling - Clear data presentation optimized for clinical research
The JAMA theme offers conservative, professional styling appropriate for clinical publications.
p_jama <- lplot(demo_data,
efficacy ~ visit | treatment,
cluster_var = "subject_id",
baseline_value = 0,
theme = "jama",
title = "Clinical Efficacy Over Time",
subtitle = "JAMA Theme with Official Colors",
xlab = "Week",
ylab = "Efficacy Score (points)")
p_jama
JAMA Theme Features: - Conservative color palette with dark blue-grey (#374E55) and orange (#DF8F44) - Professional typography suitable for medical publications - Clear, readable design for clinical data
The Science theme provides modern scientific styling with the journal’s official color scheme.
p_science <- lplot(demo_data,
efficacy ~ visit | treatment,
cluster_var = "subject_id",
baseline_value = 0,
theme = "science",
title = "Clinical Efficacy Over Time",
subtitle = "Science Theme with Official Colors",
xlab = "Week",
ylab = "Efficacy Score (points)")
p_science
Science Theme Features: - 7pt font size (Science requirement) - Subtle grid lines for data reading - Science color palette: Deep blue (#3B4992), Red (#EE0000), Green (#008B45)
The JCO theme is specifically designed for oncology and clinical research publications.
p_jco <- lplot(demo_data,
efficacy ~ visit | treatment,
cluster_var = "subject_id",
baseline_value = 0,
theme = "jco",
title = "Clinical Efficacy Over Time",
subtitle = "JCO Theme with Official Colors",
xlab = "Week",
ylab = "Efficacy Score (points)")
p_jco
JCO Theme Features: - Clinical blue (#0073C2) and yellow (#EFC000) color scheme - Designed specifically for oncology research - Professional medical styling
The FDA theme provides high-contrast styling suitable for regulatory submissions.
p_fda <- lplot(demo_data,
efficacy ~ visit | treatment,
cluster_var = "subject_id",
baseline_value = 0,
theme = "fda",
title = "Clinical Efficacy Over Time",
subtitle = "FDA Theme for Regulatory Submissions",
xlab = "Week",
ylab = "Efficacy Score (points)")
p_fda
FDA Theme Features: - High contrast for regulatory review - 10pt font size for readability - Grid lines for precise data reading - Conservative, professional appearance
Let’s create a comprehensive comparison showing multiple themes side by side:
# Create simplified plots for comparison
create_comparison_plot <- function(theme_name, title_suffix) {
lplot(demo_data,
efficacy ~ visit | treatment,
cluster_var = "subject_id",
baseline_value = 0,
theme = theme_name,
title = paste("Efficacy Analysis -", title_suffix),
xlab = "Week",
ylab = "Efficacy (pts)")
}
# Create all theme variations
p1 <- create_comparison_plot("nejm", "NEJM")
p2 <- create_comparison_plot("nature", "Nature")
p3 <- create_comparison_plot("lancet", "Lancet")
p4 <- create_comparison_plot("jama", "JAMA")
p5 <- create_comparison_plot("science", "Science")
p6 <- create_comparison_plot("jco", "JCO")
# Arrange in grid
(p1 + p2 + p3) / (p4 + p5 + p6)
All themes work with both error bars and error bands. Here’s a comparison:
# Error bars (default)
p_bars <- lplot(demo_data,
efficacy ~ visit | treatment,
cluster_var = "subject_id",
baseline_value = 0,
theme = "nature",
error_type = "bar",
jitter_width = 0.15,
title = "Error Bars with Jitter",
xlab = "Week",
ylab = "Efficacy Score")
# Error bands
p_bands <- lplot(demo_data,
efficacy ~ visit | treatment,
cluster_var = "subject_id",
baseline_value = 0,
theme = "nature",
error_type = "band",
title = "Error Bands (Ribbons)",
xlab = "Week",
ylab = "Efficacy Score")
p_bars + p_bands
The zzlongplot package supports multiple summary
statistics to display your data:
# Create test data with some variability
set.seed(42)
n_subjects <- 40
stats_demo <- data.frame(
subject_id = rep(1:n_subjects, each = 4),
visit = rep(c(0, 4, 8, 12), times = n_subjects),
efficacy = c(
rnorm(n_subjects, mean = 50, sd = 8), # baseline
rnorm(n_subjects, mean = 52, sd = 9), # visit 4
rnorm(n_subjects, mean = 55, sd = 10), # visit 8
rnorm(n_subjects, mean = 58, sd = 11) # visit 12
),
treatment = rep(c("Placebo", "Treatment"), each = 80)
)
# Mean ± 95% CI
p_mean_ci <- lplot(stats_demo, efficacy ~ visit | treatment,
cluster_var = "subject_id", baseline_value = 0,
summary_statistic = "mean", confidence_interval = 0.95,
theme = "nature",
title = "Mean ± 95% CI",
xlab = "Week", ylab = "Efficacy Score")
# Mean ± SE (Standard Error)
p_mean_se <- lplot(stats_demo, efficacy ~ visit | treatment,
cluster_var = "subject_id", baseline_value = 0,
summary_statistic = "mean_se",
theme = "nature",
title = "Mean ± SE",
xlab = "Week", ylab = "Efficacy Score")
# Median + IQR (Interquartile Range)
p_median <- lplot(stats_demo, efficacy ~ visit | treatment,
cluster_var = "subject_id", baseline_value = 0,
summary_statistic = "median",
theme = "nature",
title = "Median + IQR",
xlab = "Week", ylab = "Efficacy Score")
# Boxplot summary (Quartiles + Whiskers)
p_boxplot <- lplot(stats_demo, efficacy ~ visit | treatment,
cluster_var = "subject_id", baseline_value = 0,
summary_statistic = "boxplot",
theme = "nature",
title = "Boxplot Summary",
xlab = "Week", ylab = "Efficacy Score")
# Arrange all plots
(p_mean_ci + p_mean_se) / (p_median + p_boxplot)
When to use each option:
summary_statistic = "mean" (default):
confidence_interval specified,
otherwise SEsummary_statistic = "mean_se":
summary_statistic = "median":
summary_statistic = "boxplot":
You can override journal colors with colorblind-friendly palettes:
# Use journal theme but override with accessible colors
p_accessible <- lplot(demo_data,
efficacy ~ visit | treatment,
cluster_var = "subject_id",
baseline_value = 0,
theme = "nejm", # NEJM typography
treatment_colors = "standard", # Colorblind-friendly treatment colors
title = "NEJM Theme + Colorblind-Friendly Colors",
xlab = "Week",
ylab = "Efficacy Score")
p_accessible
# Journal-specific palettes (auto-applied with themes)
lplot(data, form, theme = "nejm") # NEJM colors
lplot(data, form, theme = "nature") # Nature colors
lplot(data, form, theme = "lancet") # Lancet colors
# Clinical palettes (manual specification)
lplot(data, form, treatment_colors = "standard") # Clinical trial colors
lplot(data, form, color_palette = clinical_colors("severity")) # Severity progression
lplot(data, form, color_palette = clinical_colors("fda")) # FDA high-contrast
# Custom color vectors
lplot(data, form, color_palette = c("#FF0000", "#00FF00", "#0000FF"))
theme = "nejm" for clinical
trials and medical researchtheme = "nature"
or theme = "science" for basic researchtheme = "lancet" for
clinical and epidemiological studiestheme = "jama" for clinical
medicine and healthcare researchtheme = "jco" for oncology
and cancer researchtheme = "fda" for
high-contrast, regulatory-appropriate stylingtheme = "nejm" for professional medical appearancetreatment_colors = "standard" for
colorblind-friendly treatment colorserror_type = "band" to reduce visual
clutterThe zzlongplot package provides comprehensive theming
options for medical and scientific publications:
theme
parameterChoose the appropriate theme based on your target journal or regulatory requirement, and the package will automatically apply the correct styling and colors for publication-ready figures.